import Vue from 'vue'
import Router from 'vue-router'

import Home from '@/Home'
import Category from '@/Category'
import Discount from '@/Discount'
import GoodDetail from '@/GoodDetail'
import CategoryResults from '@/CategoryResults'
import GoodResults from '@/GoodResults'
import Profile from '@/Profile'
import Help from '@/Help'
import RedPacketDetail from '@/RedPacketDetail'
import Withdraw from '@/Withdraw'
import WxCallback from '@/WxCallback'
import WithdrawRecords from '@/WithdrawRecords'
import AppUrl from '@/AppUrl'

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: '/',
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/discount',
      name: 'Discount',
      component: Discount
    },
    {
      path: '/category',
      name: 'Category',
      component: Category
    },
    {
      path: '/profile',
      name: 'Profile',
      component: Profile
    },
    {
      path: '/category/results',
      name: 'CategoryResults',
      component: CategoryResults
    },
    {
      path: '/goods/search',
      name: 'GoodResults',
      component: GoodResults
    },
    {
      path: '/good/:id',
      name: 'GoodDetail',
      component: GoodDetail
    },
    {
      path: '/good_search',
      name: 'GoodSearch',
      component: GoodDetail
    },
    {
      path: '/help',
      name: 'Help',
      component: Help
    },
    {
      path: '/red_packet/:id',
      name: 'RedPacketDetail',
      component: RedPacketDetail
    },
    {
      path: '/withdraw',
      name: 'Withdraw',
      component: Withdraw
    },
    {
      path: '/withdraw/records',
      name: 'WithdrawRecords',
      component: WithdrawRecords
    },
    {
      path: '/callback',
      name: 'callback',
      component: WxCallback
    },
    {
      path: '/app',
      name: 'AppUrl',
      component: AppUrl
    }
  ],
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else if (savedPosition === null) {
      return { x: 0, y: 0 }
    }
  }
})
